// question : 使用_average重构averageDollarValue
const fp = require('lodash/fp')
const cars = [
    {price:1001,name:'Audi A4L'},
    {price:1002,name:'Audi A5'},
    {price:1003,name:'Audi A6L'},
    {price:1004,name:'Audi A7'},
    {price:1005,name:'Audi A8L'},
]
let _average = function (xs) {
    return fp.reduce(fp.add,0,xs) / xs.length
}
// let averageDollarValue = function (cars) {
//     let price_values = fp.map(function (car) {
//         return car.price
//     },cars)
//     return _average(price_values)
// }
const getPrices = (arr)=>{
    return arr.map(t=>t.price)
}
function compose(f,g){
    // 返回一个新函数
    return function(x){
        return f(g(x))
    }
}
let t =  compose(_average,getPrices)
console.log(t(cars))